package com.ruoyi.tranShort.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tranShort.domain.ShortClassGrade;
import com.ruoyi.tranShort.service.IShortClassGradeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 班别管理Controller
 * 
 * @author ruoyi
 * @date 2021-08-15
 */
@RestController
@RequestMapping("/tranShort/classGrade")
public class ShortClassGradeController extends BaseController
{
    @Autowired
    private IShortClassGradeService shortClassGradeService;

    /**
     * 查询班别管理列表
     */
    @PreAuthorize("@ss.hasPermi('tranShort:classGrade:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShortClassGrade shortClassGrade)
    {
        startPage();
        List<ShortClassGrade> list = shortClassGradeService.selectShortClassGradeList(shortClassGrade);
        return getDataTable(list);
    }

    /**
     * 导出班别管理列表
     */
    @PreAuthorize("@ss.hasPermi('tranShort:classGrade:export')")
    @Log(title = "班别管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ShortClassGrade shortClassGrade)
    {
        List<ShortClassGrade> list = shortClassGradeService.selectShortClassGradeList(shortClassGrade);
        ExcelUtil<ShortClassGrade> util = new ExcelUtil<ShortClassGrade>(ShortClassGrade.class);
        return util.exportExcel(list, "班别管理数据");
    }

    /**
     * 获取班别管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('tranShort:classGrade:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(shortClassGradeService.selectShortClassGradeById(id));
    }

    /**
     * 新增班别管理
     */
    @PreAuthorize("@ss.hasPermi('tranShort:classGrade:add')")
    @Log(title = "班别管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShortClassGrade shortClassGrade)
    {
        return toAjax(shortClassGradeService.insertShortClassGrade(shortClassGrade));
    }

    /**
     * 修改班别管理
     */
    @PreAuthorize("@ss.hasPermi('tranShort:classGrade:edit')")
    @Log(title = "班别管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShortClassGrade shortClassGrade)
    {
        return toAjax(shortClassGradeService.updateShortClassGrade(shortClassGrade));
    }

    /**
     * 删除班别管理
     */
    @PreAuthorize("@ss.hasPermi('tranShort:classGrade:remove')")
    @Log(title = "班别管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shortClassGradeService.deleteShortClassGradeByIds(ids));
    }

    /**
     * 获取全部
     * @return
     */
    @GetMapping("/getAll")
    public AjaxResult getAll(){
        List<ShortClassGrade> list = shortClassGradeService.selectShortClassGradeList(new ShortClassGrade());
        return AjaxResult.success(list);
    }
}
